package com.czk.config;

import com.czk.aop.DoJointPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 将对象注入容器
 *
 * @Author:ChenZhangKun
 * @Date: 2021/8/9 11:33
 */
@Configuration
@ConditionalOnClass(StarterService.class)
@EnableConfigurationProperties(StartServiceProperties.class)
//@ComponentScan(basePackages = {"com.czk.aop"}) // 添加扫描aop的注解
public class StarterAutoConfigure {
    @Autowired
    private StartServiceProperties startServiceProperties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "czk.door", value = "enabled", havingValue = "true")
    StarterService starterService() {
        System.out.println("startServiceProperties"+"被注入了");
        return new StarterService(startServiceProperties.getUserStr());
    }

    @Bean
    public DoJointPoint doJointPoint(){
        return new DoJointPoint();
    }
}
